<template>
	<view>
		<u-swiper :list="list3" indicatorMode="line" circular></u-swiper>
		<!-- 云端unicloud-db获取热门岗位 -->
		<unicloud-db ref="jobRef" v-slot:default="{data,loading,error,options}" collection="company">
			<view v-if="error">{{error.message}}</view>
			<view v-else>
				<u-card title="招聘企业">
					<view slot="body">
						<view class="wrap">
							<u-row gutter="16">
								<u-col span="3" v-for="i of data">
									<u-image width="100%" height="100rpx" :src="i.image" @click="enterCompany(i._id)"></u-image>
									<view class="demo-layout bg-purple"@click="enterCompany(i._id)">{{i.comapny_name}}</view>
									<!-- <view class="demo-layout bg-purple" @click="reItem(i._id)" >删除</view> -->
								</u-col>
							</u-row>
						</view>
					</view>
				</u-card>
			</view>
		</unicloud-db>


		<u-card title="热门岗位">
			<view slot="body">
				<view class="wrap">
					<u-row gutter="16">
						<u-col span="3" v-for="n in categoryList">
							<view class="demo-layout bg-purple" @click="enterHotJob(n._id)">{{n.category_name}}</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<!-- <u-button @click="test">测试所有</u-button> -->
		    </navigator>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				src: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-res.zhipin.com%2Fjrs%2Fec611cf08d96f237a5ae65da18b688b0.jpg&refer=http%3A%2F%2Fc-res.zhipin.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1641040649&t=041429b07197764d5514e6a70d1f57cf',
				title: 'Hello',
				list3: [
					'https://img1.baidu.com/it/u=196369141,2250762960&fm=26&fmt=auto',
					'https://img2.baidu.com/it/u=1883633414,3967799278&fm=26&fmt=auto',
				],
				form: {
					job_name: '',

				},
				//岗位类别列表
				categoryList: [],
			}
		},
		onLoad() {
			//获取工作列表
			this.showJobs()
			this.$u.get()
		},
		methods: {
			//根据id删除
			reItem(id) {
				// console.log(id)
				//数据库job表根据id删除
				this.$refs.jobRef.remove(id)
				// console.log()
			},
			//添加一个记录
			addJob() {

			},
			//获取job所用数据
			showJobs() {
				uniCloud.callFunction({
					name: "category",
					data: {
						type: "category"
					},
					success: (res) => {
						this.categoryList = res.result.data
					},
					fail: (err) => {
						console.log(err)
					}
				})
			},
			
			//跳转并相关热门岗位
			enterHotJob(categoryId){
				// console.log(categoryId)
				 uni.setStorageSync("hotjob_nowCategoryId",categoryId)
				 uni.navigateTo({
				    url:'/pages/hotjob/hotjob'
				  })
			},
			enterCompany(companyId){
				//将id设置进本地存储机制
				uni.setStorageSync("hotjob_nowCompanyId",companyId)
				uni.navigateTo({
				   url:'/pages/company/company'
				 })
			},
			test(){
				uniCloud.callFunction({
								name: "job",
								data: {
									data:'',
									type: "selectByArr"
								},
								success: (res) => {
									// console.log("error！",res);
									if(res.result.status!=200){
										return;
									}
									//成功
									//赋值
									
									
								},
								fail: (err) => {
									console.log(err)
								}
							})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 40rpx;
		// background-color: yellow;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 100rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 28rpx;
		color: $u-content-color;
	}

	.link-demo {
		margin-top: 80rpx;
	}

	.demo-layout {
		height: 80rpx;
		border-radius: 8rpx;
		// margin-top: 10rpx;
	}

	.bg-purple {
		text-align: center;
		line-height: 80rpx;
		// background: #d3dce6;

	}
</style>
